package com.huashi.otg.sdk;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory.Options;
import android.graphics.Paint.Align;
import android.graphics.Paint.Style;
import android.graphics.PorterDuff.Mode;
import android.os.Environment;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class GetImg {
	static SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

	public GetImg() {
	}

	public static void saveMyBitmap(String path) {
		try {
			FileInputStream fis = new FileInputStream(
					Environment.getExternalStorageDirectory().getAbsolutePath() + "/wltlib/zp.bmp");
			Bitmap mBitmap = BitmapFactory.decodeStream(fis);
			fis.close();
			File f = new File(path);
			if (f.exists()) {
				f.delete();
			}

			FileOutputStream fOut = null;
			fOut = new FileOutputStream(f);
			mBitmap.compress(CompressFormat.PNG, 100, fOut);
			fOut.flush();
			fOut.close();
		} catch (Exception var5) {
			var5.printStackTrace();
		}

	}

	public static Bitmap compositeImages(Bitmap srcBitmap, Bitmap dstBitmap) {
		Bitmap bmp = null;
		bmp = Bitmap.createBitmap(srcBitmap.getWidth(), srcBitmap.getHeight() + dstBitmap.getHeight(),
				srcBitmap.getConfig());
		Paint paint = new Paint();
		Canvas canvas = new Canvas(bmp);
		canvas.drawBitmap(srcBitmap, 0.0F, 0.0F, paint);
		paint.setXfermode(new PorterDuffXfermode(Mode.DARKEN));
		canvas.drawBitmap(dstBitmap, 0.0F, (float) (srcBitmap.getHeight() + 1), paint);
		return bmp;
	}

	public static Bitmap compositeImages(String path1, String path2, String Outpath) {
		try {
			FileInputStream fis = new FileInputStream(path1);
			Bitmap Bitmap1 = BitmapFactory.decodeStream(fis);
			fis.close();
			Bitmap Bitmap2 = getimage(path2);
			Bitmap bmp = null;
			bmp = Bitmap.createBitmap(Bitmap1.getWidth(), Bitmap1.getHeight() + Bitmap2.getHeight() + 50,
					Bitmap1.getConfig());
			Paint paint = new Paint();
			Canvas canvas = new Canvas(bmp);
			canvas.drawBitmap(Bitmap1, 0.0F, 0.0F, paint);
			int bsC = Color.argb(0, 0, 0, 0);
			paint = new Paint(1);
			paint.setTextAlign(Align.LEFT);
			paint.setColor(bsC);
			paint.setAntiAlias(true);
			paint.setDither(true);
			paint.setAlpha(255);
			paint.setStyle(Style.FILL);
			paint.setTextSize(13.0F);
			Date date = new Date();
			String StrText = df.format(date);
			int Num = 1;
			canvas.drawText("进入时间：" + StrText, 0.0F, (float) (Bitmap1.getHeight() + Num * 13), paint);
			Num = Num + 1;
			canvas.drawText("进入类型：进入", 0.0F, (float) (Bitmap1.getHeight() + Num * 13), paint);
			++Num;
			canvas.drawText("车牌号：", 0.0F, (float) (Bitmap1.getHeight() + Num * 13), paint);
			++Num;
			canvas.drawText("上报状态：未上报", 0.0F, (float) (Bitmap1.getHeight() + Num * 13), paint);
			paint.setXfermode(new PorterDuffXfermode(Mode.DARKEN));
			canvas.drawBitmap(Bitmap2, 0.0F, (float) (Bitmap1.getHeight() + Num * 13 + 6), paint);
			FileOutputStream Bos = null;

			try {
				File BdestFile = new File(Outpath + "/" + StrText + ".bmp");
				BdestFile.createNewFile();
				Bos = new FileOutputStream(BdestFile);
				bmp.compress(CompressFormat.JPEG, 100, Bos);
			} catch (FileNotFoundException var27) {
			} catch (IOException var28) {
				var28.printStackTrace();
			} finally {
				if (Bos != null) {
					try {
						Bos.flush();
						Bos.close();
					} catch (IOException var26) {
					}
				}

			}

			return bmp;
		} catch (FileNotFoundException var30) {
			var30.printStackTrace();
		} catch (IOException var31) {
			var31.printStackTrace();
		}

		return null;
	}

	/**
	 * 功能：生成身份证、港澳台、外国人正反面
	 * 
	 * @param info    身份证信息对象
	 * @param context 当前对象
	 * @param type    0 ：不生成图片 1 ：在指定路径下生成 姓名.bmp图片
	 * @param BmpPath 生成路径
	 * @param bmphead 头像Bitmap数据
	 * @return 返回值：生成身份证正反面图片的Bitmap格式数据
	 * @throws IOException 异常需要捕获
	 */
	public static Bitmap ShowBmp(HSIDCardInfo info, Context context, int type, String BmpPath, Bitmap bmphead)
			throws IOException {
		if (info.getcertType() == "J") {
			return ShowHKBmp(info, context, type, BmpPath, bmphead);
		} else if (info.getcertType() == "I") {
			return ShowForeignerBmp(info, context, type, BmpPath, bmphead);
		} else {
			Paint mPaint = new Paint();
			if (info.getPeopleName() == "1") {
				return null;
			} else {
				SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
				Bitmap bmpF = BitmapFactory.decodeStream(context.getResources().getAssets().open("f.bmp"));
				int FcvWidth = bmpF.getWidth();
				int FcvHeight = bmpF.getHeight();
				Bitmap newbmpF = Bitmap.createBitmap(FcvWidth, FcvHeight, Config.RGB_565);
				float FontMultf = (float) (FcvHeight * FcvHeight + FcvWidth * FcvWidth) / 152341.0F;
				FontMultf = (float) Math.sqrt((double) FontMultf);
				float xMultF = (float) FcvWidth / 329.0F;
				float yMultF = (float) FcvHeight / 210.0F;
				Canvas Fcv = new Canvas(newbmpF);
				Fcv.drawBitmap(bmpF, 0.0F, 0.0F, mPaint);
				int bsC = Color.argb(0, 71, 95, 155);
				Paint Fp = new Paint(1);
				Fp.setTextAlign(Align.LEFT);
				Fp.setColor(bsC);
				Fp.setAntiAlias(true);
				Fp.setDither(true);
				Fp.setAlpha(255);
				Fp.setStyle(Style.FILL);
				Fp.setTextSize(13.0F * FontMultf);
				Fcv.drawText("姓  名", 23.0F * xMultF, 39.0F * yMultF, Fp);
				Fcv.drawText("性  别", 23.0F * xMultF, 66.0F * yMultF, Fp);
				Fcv.drawText("民  族", 98.0F * xMultF, 66.0F * yMultF, Fp);
				Fcv.drawText("出  生", 23.0F * xMultF, 92.0F * yMultF, Fp);
				Fcv.drawText("年", 98.0F * xMultF, 92.0F * yMultF, Fp);
				Fcv.drawText("月", 131.0F * xMultF, 92.0F * yMultF, Fp);
				Fcv.drawText("日", 165.0F * xMultF, 92.0F * yMultF, Fp);
				Fcv.drawText("住  址", 23.0F * xMultF, 115.0F * yMultF, Fp);
				Fcv.drawText("公民身份号码", 23.0F * xMultF, 184.0F * yMultF, Fp);
				Fp.setColor(-16777216);
				Fp.setTextSize(14.0F * FontMultf);
				Fcv.drawText(info.getPeopleName(), 66.0F * xMultF, 38.0F * yMultF, Fp);
				Fp.setTextSize(13.0F * FontMultf);
				Fcv.drawText(info.getSex(), 66.0F * xMultF, 65.0F * yMultF, Fp);
				Fcv.drawText(info.getPeople(), 138.0F * xMultF, 65.0F * yMultF, Fp);
				String str = df.format(info.getBirthDay());
				Fcv.drawText(str.substring(0, 4), 66.0F * xMultF, 92.0F * yMultF, Fp);
				if (str.substring(4, 5).endsWith("0")) {
					Fcv.drawText(str.substring(5, 6), 119.0F * xMultF, 92.0F * yMultF, Fp);
				} else {
					Fcv.drawText(str.substring(4, 6), 116.0F * xMultF, 92.0F * yMultF, Fp);
				}

				if (str.substring(6, 7).endsWith("0")) {
					Fcv.drawText(str.substring(7, 8), 153.0F * xMultF, 92.0F * yMultF, Fp);
				} else {
					Fcv.drawText(str.substring(6, 8), 150.0F * xMultF, 92.0F * yMultF, Fp);
				}

				String straddr = info.getAddr();
				String straddr1 = "";
				String straddr2 = "";
				String straddr3 = "";
				double AddLenth = 0.0D;

				for (int i = 0; i < straddr.length(); ++i) {
					if (Character.isDigit(straddr.charAt(i))) {
						AddLenth += 0.5D;
					} else {
						++AddLenth;
					}

					if (AddLenth <= 11.0D) {
						straddr1 = straddr1 + straddr.charAt(i);
					} else if (AddLenth <= 22.0D) {
						straddr2 = straddr2 + straddr.charAt(i);
					} else {
						straddr3 = straddr3 + straddr.charAt(i);
					}
				}

				Fcv.drawText(straddr1, 66.0F * xMultF, 115.0F * yMultF, Fp);
				Fcv.drawText(straddr2, 66.0F * xMultF, 137.0F * yMultF, Fp);
				Fcv.drawText(straddr3, 66.0F * xMultF, 157.0F * yMultF, Fp);
				Fp.setTextSize(14.0F * FontMultf);
				Fp.setTypeface(Typeface.DEFAULT_BOLD);
				Fp.setStrokeWidth(3.0F);
				Fp.setTextScaleX(1.2F);
				Fcv.drawText(info.getIDCard(), 115.0F * xMultF, 183.0F * yMultF, Fp);
				Fcv.save(31);
				Fcv.restore();
				Matrix matrix = new Matrix();
				matrix.postScale(xMultF, yMultF);
				int colorflage = bmphead.getPixel(5, 5);
				Paint phead = new Paint();

				for (int i = 0; i < bmphead.getWidth(); ++i) {
					for (int j = 0; j < bmphead.getHeight() - 3; ++j) {
						if (bmphead.getPixel(i, j) != colorflage) {
							phead.setColor(bmphead.getPixel(i, j));
							Fcv.drawPoint(211.0F * xMultF + (float) i, 31.0F * yMultF + (float) j, phead);
						}
					}
				}

				phead.reset();
				Fcv.save(31);
				Fcv.restore();
				FileOutputStream Fos = null;

				try {
					File FdestFile = new File(BmpPath + "/idcardF.bmp");
					FdestFile.createNewFile();
					Fos = new FileOutputStream(FdestFile);
					newbmpF.compress(CompressFormat.JPEG, 100, Fos);
				} catch (FileNotFoundException var116) {
				} catch (IOException var117) {
					var117.printStackTrace();
				} finally {
					if (Fos != null) {
						try {
							Fos.flush();
							Fos.close();
						} catch (IOException var107) {
						}
					}

				}

				Bitmap bmpB = BitmapFactory.decodeStream(context.getResources().getAssets().open("b.bmp"));
				Bitmap newbmpB = Bitmap.createBitmap(bmpB.getWidth(), bmpB.getHeight(), Config.ARGB_8888);
				int BcvWidth = bmpF.getWidth();
				int BcvHeight = bmpF.getHeight();
				float FontMultB = (float) (BcvWidth * BcvWidth + BcvHeight * BcvHeight) / 152341.0F;
				FontMultB = (float) Math.sqrt((double) FontMultB);
				float xMultB = (float) BcvWidth / 329.0F;
				float yMultB = (float) BcvHeight / 210.0F;
				Canvas Bcv = new Canvas(newbmpB);
				Bcv.drawBitmap(bmpB, 0.0F, 0.0F, mPaint);
				Fp.reset();
				Fp.setTextAlign(Align.LEFT);
				Fp.setColor(-16777216);
				Fp.setAntiAlias(true);
				Fp.setDither(true);
				Fp.setAlpha(255);
				Fp.setStyle(Style.FILL);
				Fp.setTextSize(13.0F * FontMultB);
				Fp.setTypeface(Typeface.DEFAULT_BOLD);
				Bcv.drawText("签发机关", 68.0F * xMultB, 169.0F * yMultB, Fp);
				Bcv.drawText("有效期限", 68.0F * xMultB, 193.0F * yMultB, Fp);
				Fp.setTypeface(Typeface.DEFAULT);
				Bcv.drawText(info.getDepartment(), 130.0F * xMultB, 169.0F * yMultB, Fp);
				String tmpstr = info.getStrartDate() + "-" + info.getEndDate();
				Bcv.drawText(tmpstr, 130.0F * xMultB, 193.0F * yMultB, Fp);
				Bcv.save(31);
				Bcv.restore();
				FileOutputStream Bos = null;

				try {
					File BdestFile = new File(BmpPath + "/idcardB.bmp");
					BdestFile.createNewFile();
					Bos = new FileOutputStream(BdestFile);
					newbmpB.compress(CompressFormat.JPEG, 100, Bos);
				} catch (FileNotFoundException var114) {
				} catch (IOException var115) {
					var115.printStackTrace();
				} finally {
					if (Bos != null) {
						try {
							Bos.flush();
							Bos.close();
						} catch (IOException var108) {
						}
					}

				}

				FileInputStream fis = null;

				try {
					fis = new FileInputStream(BmpPath + "/idcardF.bmp");
				} catch (FileNotFoundException var113) {
					var113.printStackTrace();
				}

				Bitmap bmp = BitmapFactory.decodeStream(fis);
				fis.close();
				FileInputStream fisB = null;

				try {
					fisB = new FileInputStream(BmpPath + "/idcardB.bmp");
				} catch (FileNotFoundException var112) {
					var112.printStackTrace();
				}

				Bitmap bmpBB = BitmapFactory.decodeStream(fisB);
				fisB.close();
				Bitmap newbmp = null;
				newbmp = compositeImages(bmp, bmpBB);
				if (type != 1) {
					return newbmp;
				} else {
					String name = info.getPeopleName().trim();

					try {
						File BdestFile = new File(BmpPath + "/" + name + ".bmp");
						BdestFile.createNewFile();
						Bos = new FileOutputStream(BdestFile);
						newbmp.compress(CompressFormat.JPEG, 100, Bos);
					} catch (FileNotFoundException var110) {
					} catch (IOException var111) {
						var111.printStackTrace();
					} finally {
						if (Bos != null) {
							try {
								Bos.flush();
								Bos.close();
							} catch (IOException var109) {
							}
						}

					}

					return newbmp;
				}
			}
		}
	}

	public static Bitmap ShowHKBmp(HSIDCardInfo info, Context context, int type, String BmpPath, Bitmap bmphead)
			throws IOException {
		Paint mPaint = new Paint();
		if (info.getPeopleName() == "1") {
			return null;
		} else {
			SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
			Bitmap bmpF = BitmapFactory.decodeStream(context.getResources().getAssets().open("HKZ.bmp"));
			int FcvWidth = bmpF.getWidth();
			int FcvHeight = bmpF.getHeight();
			Bitmap newbmpF = Bitmap.createBitmap(FcvWidth, FcvHeight, Config.RGB_565);
			float FontMultf = (float) (FcvHeight * FcvHeight + FcvWidth * FcvWidth) / 152341.0F;
			FontMultf = (float) Math.sqrt((double) FontMultf);
			float xMultF = (float) FcvWidth / 329.0F;
			float yMultF = (float) FcvHeight / 210.0F;
			Canvas Fcv = new Canvas(newbmpF);
			Fcv.drawBitmap(bmpF, 0.0F, 0.0F, mPaint);
			int bsC = Color.argb(0, 71, 95, 155);
			Paint Fp = new Paint(1);
			Fp.setTextAlign(Align.LEFT);
			Fp.setColor(bsC);
			Fp.setAntiAlias(true);
			Fp.setDither(true);
			Fp.setAlpha(255);
			Fp.setStyle(Style.FILL);
			Fp.setTextSize(13.0F * FontMultf);
			Fp.setColor(-16777216);
			Fp.setTextSize(12.0F * FontMultf);
			Fcv.drawText(info.getPeopleName(), 66.0F * xMultF, 42.0F * yMultF, Fp);
			Fcv.drawText(info.getSex(), 66.0F * xMultF, 66.0F * yMultF, Fp);
			String str = df.format(info.getBirthDay());
			Fcv.drawText(str.substring(0, 4), 66.0F * xMultF, 92.0F * yMultF, Fp);
			if (str.substring(4, 5).endsWith("0")) {
				Fcv.drawText(str.substring(5, 6), 119.0F * xMultF, 92.0F * yMultF, Fp);
			} else {
				Fcv.drawText(str.substring(4, 6), 116.0F * xMultF, 92.0F * yMultF, Fp);
			}

			if (str.substring(6, 7).endsWith("0")) {
				Fcv.drawText(str.substring(7, 8), 149.0F * xMultF, 92.0F * yMultF, Fp);
			} else {
				Fcv.drawText(str.substring(6, 8), 146.0F * xMultF, 92.0F * yMultF, Fp);
			}

			String straddr = info.getAddr();
			String straddr1 = "";
			String straddr2 = "";
			String straddr3 = "";
			double AddLenth = 0.0D;

			for (int i = 0; i < straddr.length(); ++i) {
				if (Character.isDigit(straddr.charAt(i))) {
					AddLenth += 0.5D;
				} else {
					++AddLenth;
				}

				if (AddLenth <= 11.0D) {
					straddr1 = straddr1 + straddr.charAt(i);
				} else if (AddLenth <= 22.0D) {
					straddr2 = straddr2 + straddr.charAt(i);
				} else {
					straddr3 = straddr3 + straddr.charAt(i);
				}
			}

			Fcv.drawText(straddr1, 66.0F * xMultF, 115.0F * yMultF, Fp);
			Fcv.drawText(straddr2, 66.0F * xMultF, 137.0F * yMultF, Fp);
			Fcv.drawText(straddr3, 66.0F * xMultF, 157.0F * yMultF, Fp);
			Fp.setTextSize(14.0F * FontMultf);
			Fp.setTypeface(Typeface.DEFAULT_BOLD);
			Fp.setStrokeWidth(3.0F);
			Fp.setTextScaleX(1.2F);
			Fcv.drawText(info.getIDCard(), 115.0F * xMultF, 183.0F * yMultF, Fp);
			Fcv.save(31);
			Fcv.restore();
			Matrix matrix = new Matrix();
			matrix.postScale(xMultF, yMultF);
			Paint phead = new Paint();

			for (int i = 0; i < bmphead.getWidth(); ++i) {
				for (int j = 0; j < bmphead.getHeight() - 3; ++j) {
					int colorflage = bmphead.getPixel(i, j);
					int A = Color.alpha(colorflage);
					int R = Color.red(colorflage);
					int G = Color.green(colorflage);
					int B = Color.blue(colorflage);
					if (R <= 236 || G <= 236 || B <= 236) {
						phead.setColor(bmphead.getPixel(i, j));
						Fcv.drawPoint(211.0F * xMultF + (float) i, 31.0F * yMultF + (float) j, phead);
					}
				}
			}

			phead.reset();
			Fcv.save(31);
			Fcv.restore();
			FileOutputStream Fos = null;

			try {
				File FdestFile = new File(BmpPath + "/idcardF.bmp");
				FdestFile.createNewFile();
				Fos = new FileOutputStream(FdestFile);
				newbmpF.compress(CompressFormat.JPEG, 100, Fos);
			} catch (FileNotFoundException var122) {
			} catch (IOException var123) {
				var123.printStackTrace();
			} finally {
				if (Fos != null) {
					try {
						Fos.flush();
						Fos.close();
					} catch (IOException var114) {
					}
				}

			}

			String tmpID = info.getIDCard();
			String DTFile;
			if (tmpID.substring(0, 4) == "8300") {
				DTFile = "TWB.bmp";
			} else {
				DTFile = "HKB.bmp";
			}

			Bitmap bmpB = BitmapFactory.decodeStream(context.getResources().getAssets().open(DTFile));
			Bitmap newbmpB = Bitmap.createBitmap(bmpB.getWidth(), bmpB.getHeight(), Config.ARGB_8888);
			int BcvWidth = bmpF.getWidth();
			int BcvHeight = bmpF.getHeight();
			float FontMultB = (float) (BcvWidth * BcvWidth + BcvHeight * BcvHeight) / 152341.0F;
			FontMultB = (float) Math.sqrt((double) FontMultB);
			float xMultB = (float) BcvWidth / 329.0F;
			float yMultB = (float) BcvHeight / 210.0F;
			Canvas Bcv = new Canvas(newbmpB);
			Bcv.drawBitmap(bmpB, 0.0F, 0.0F, mPaint);
			Fp.reset();
			Fp.setTextAlign(Align.LEFT);
			Fp.setColor(-16777216);
			Fp.setAntiAlias(true);
			Fp.setDither(true);
			Fp.setAlpha(255);
			Fp.setStyle(Style.FILL);
			Fp.setTextSize(12.0F * FontMultB);
			Fp.setTypeface(Typeface.DEFAULT_BOLD);
			Fp.setTypeface(Typeface.DEFAULT);
			Bcv.drawText(info.getDepartment(), 138.0F * xMultB, 156.0F * yMultB, Fp);
			Bcv.drawText(info.getissuesNum(), 266.0F * xMultB, 156.0F * yMultB, Fp);
			String tmpstr = info.getStrartDate() + "-" + info.getEndDate();
			Bcv.drawText(tmpstr, 138.0F * xMultB, 169.0F * yMultB, Fp);
			Bcv.drawText(info.getPassCheckID(), 138.0F * xMultB, 182.0F * yMultB, Fp);
			Bcv.save(31);
			Bcv.restore();
			FileOutputStream Bos = null;

			try {
				File BdestFile = new File(BmpPath + "/idcardB.bmp");
				BdestFile.createNewFile();
				Bos = new FileOutputStream(BdestFile);
				newbmpB.compress(CompressFormat.JPEG, 100, Bos);
			} catch (FileNotFoundException var120) {
			} catch (IOException var121) {
				var121.printStackTrace();
			} finally {
				if (Bos != null) {
					try {
						Bos.flush();
						Bos.close();
					} catch (IOException var115) {
					}
				}

			}

			FileInputStream fis = null;

			try {
				fis = new FileInputStream(BmpPath + "/idcardF.bmp");
			} catch (FileNotFoundException var119) {
				var119.printStackTrace();
			}

			Bitmap bmp = BitmapFactory.decodeStream(fis);
			fis.close();
			FileInputStream fisB = null;

			try {
				fisB = new FileInputStream(BmpPath + "/idcardB.bmp");
			} catch (FileNotFoundException var118) {
				var118.printStackTrace();
			}

			Bitmap bmpBB = BitmapFactory.decodeStream(fisB);
			fisB.close();
			Bitmap newbmp = null;
			newbmp = compositeImages(bmp, bmpBB);
			if (type != 1) {
				return newbmp;
			} else {
				String name = info.getPeopleName().trim();

				try {
					File BdestFile = new File(BmpPath + "/" + name + ".bmp");
					BdestFile.createNewFile();
					Bos = new FileOutputStream(BdestFile);
					newbmp.compress(CompressFormat.JPEG, 100, Bos);
				} catch (FileNotFoundException var116) {
				} catch (IOException var117) {
					var117.printStackTrace();
				} finally {
					if (Bos != null) {
						try {
							Bos.flush();
							Bos.close();
						} catch (IOException var113) {
						}
					}

				}

				return newbmp;
			}
		}
	}

	public static Bitmap ShowForeignerBmp(HSIDCardInfo info, Context context, int type, String BmpPath, Bitmap bmphead)
			throws IOException {
		Paint mPaint = new Paint();
		SimpleDateFormat df = new SimpleDateFormat("yyyy.MM.dd");
		Bitmap bmpF = BitmapFactory.decodeStream(context.getResources().getAssets().open("FZ.bmp"));
		int FcvWidth = bmpF.getWidth();
		int FcvHeight = bmpF.getHeight();
		Bitmap newbmpF = Bitmap.createBitmap(FcvWidth, FcvHeight, Config.RGB_565);
		float FontMultf = (float) (FcvHeight * FcvHeight + FcvWidth * FcvWidth) / 152341.0F;
		FontMultf = (float) Math.sqrt((double) FontMultf);
		float xMultF = (float) FcvWidth / 329.0F;
		float yMultF = (float) FcvHeight / 210.0F;
		Canvas Fcv = new Canvas(newbmpF);
		Fcv.drawBitmap(bmpF, 0.0F, 0.0F, mPaint);
		int bsC = Color.argb(0, 71, 95, 155);
		Paint Fp = new Paint(1);
		Fp.setTextAlign(Align.LEFT);
		Fp.setColor(bsC);
		Fp.setAntiAlias(true);
		Fp.setDither(true);
		Fp.setAlpha(255);
		Fp.setStyle(Style.FILL);
		Fp.setTextSize(13.0F * FontMultf);
		Fp.setColor(-16777216);
		Fcv.drawText(info.getPeopleName(), 30.0F * xMultF, 36.0F * yMultF, Fp);
		Fcv.drawText(info.getstrChineseName(), 30.0F * xMultF, 56.0F * yMultF, Fp);
		Fp.setTextSize(12.0F * FontMultf);
		String tmpStr;
		if (info.getSex() == "女") {
			tmpStr = "女 /F";
		} else {
			tmpStr = "男 /M";
		}

		Fcv.drawText(tmpStr, 30.0F * xMultF, 84.0F * yMultF, Fp);
		String str = df.format(info.getBirthDay());
		Fcv.drawText(str, 84.0F * xMultF, 86.0F * yMultF, Fp);
		str = info.getstrNationCode() + "/" + info.getIDCard().substring(0, 3);
		Fcv.drawText(str, 30.0F * xMultF, 112.0F * yMultF, Fp);
		if (info.getEndDate() == "长期") {
			Fcv.drawText(
					info.getStrartDate().substring(0, 4) + "." + info.getStrartDate().substring(4, 6) + "."
							+ info.getStrartDate().substring(6) + "—" + info.getEndDate(),
					30.0F * xMultF, 136.0F * yMultF, Fp);
		} else {
			Fcv.drawText(
					info.getStrartDate().substring(0, 4) + "." + info.getStrartDate().substring(4, 6) + "."
							+ info.getStrartDate().substring(6) + "—" + info.getEndDate().substring(0, 4) + "."
							+ info.getEndDate().substring(4, 6) + "." + info.getEndDate().substring(6),
					30.0F * yMultF, 136.0F * yMultF, Fp);
		}

		tmpStr = info.getDepartment();
		if (tmpStr.equals("1500")) {
			tmpStr = "公安部/Ministry of Public Security";
		}

		Fcv.drawText(tmpStr, 30.0F * yMultF, 164.0F * yMultF, Fp);
		Fp.setTextSize(14.0F * FontMultf);
		Fp.setTypeface(Typeface.DEFAULT_BOLD);
		Fp.setStrokeWidth(3.0F);
		Fp.setTextScaleX(1.2F);
		Fcv.drawText(info.getIDCard(), 30.0F * xMultF, 190.0F * yMultF, Fp);
		Fcv.save(31);
		Fcv.restore();
		Matrix matrix = new Matrix();
		matrix.postScale(xMultF, yMultF);
		Paint phead = new Paint();

		for (int i = 0; i < bmphead.getWidth(); ++i) {
			for (int j = 0; j < bmphead.getHeight() - 3; ++j) {
				int colorflage = bmphead.getPixel(i, j);
				int A = Color.alpha(colorflage);
				int R = Color.red(colorflage);
				int G = Color.green(colorflage);
				int B = Color.blue(colorflage);
				if (R <= 236 || G <= 236 || B <= 236) {
					phead.setColor(bmphead.getPixel(i, j));
					Fcv.drawPoint(211.0F * xMultF + (float) i, 31.0F * yMultF + (float) j, phead);
				}
			}
		}

		phead.reset();
		Fcv.save(31);
		Fcv.restore();
		FileOutputStream Fos = null;

		try {
			File FdestFile = new File(BmpPath + "/idcardF.bmp");
			FdestFile.createNewFile();
			Fos = new FileOutputStream(FdestFile);
			newbmpF.compress(CompressFormat.JPEG, 100, Fos);
		} catch (FileNotFoundException var101) {
		} catch (IOException var102) {
			var102.printStackTrace();
		} finally {
			if (Fos != null) {
				try {
					Fos.flush();
					Fos.close();
				} catch (IOException var93) {
				}
			}

		}

		Bitmap bmpBB = BitmapFactory.decodeStream(context.getResources().getAssets().open("FB.bmp"));

		try {
			File FdestFile = new File(BmpPath + "/idcardB.bmp");
			FdestFile.createNewFile();
			Fos = new FileOutputStream(FdestFile);
			bmpBB.compress(CompressFormat.JPEG, 100, Fos);
		} catch (FileNotFoundException var99) {
		} catch (IOException var100) {
			var100.printStackTrace();
		} finally {
			if (Fos != null) {
				try {
					Fos.flush();
					Fos.close();
				} catch (IOException var94) {
				}
			}

		}

		FileInputStream fis = null;

		try {
			fis = new FileInputStream(BmpPath + "/idcardF.bmp");
		} catch (FileNotFoundException var98) {
			var98.printStackTrace();
		}

		Bitmap bmp = BitmapFactory.decodeStream(fis);
		fis.close();
		Bitmap newbmp = null;
		newbmp = compositeImages(bmp, bmpBB);
		if (type != 1) {
			return newbmp;
		} else {
			String name = info.getPeopleName().trim();
			FileOutputStream Bos = null;

			try {
				File BdestFile = new File(BmpPath + "/" + name + ".bmp");
				BdestFile.createNewFile();
				Bos = new FileOutputStream(BdestFile);
				newbmp.compress(CompressFormat.JPEG, 100, Bos);
			} catch (FileNotFoundException var96) {
			} catch (IOException var97) {
				var97.printStackTrace();
			} finally {
				if (Bos != null) {
					try {
						Bos.flush();
						Bos.close();
					} catch (IOException var95) {
					}
				}

			}

			return newbmp;
		}
	}

	public static Bitmap getimage(String srcPath) {
		Options newOpts = new Options();
		newOpts.inJustDecodeBounds = true;
		BitmapFactory.decodeFile(srcPath, newOpts);
		newOpts.inJustDecodeBounds = false;
		int w = newOpts.outWidth;
		int h = newOpts.outHeight;
		float hh = 400.0F;
		float ww = 240.0F;
		int be = 1;
		if (w > h && (float) w > ww) {
			be = (int) ((float) newOpts.outWidth / ww);
		} else if (w < h && (float) h > hh) {
			be = (int) ((float) newOpts.outHeight / hh);
		}

		if (be <= 0) {
			be = 1;
		}

		newOpts.inSampleSize = be;
		Bitmap bitmap = BitmapFactory.decodeFile(srcPath, newOpts);
		return compressImage(bitmap);
	}

	public static Bitmap compressImage(Bitmap image) {
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		image.compress(CompressFormat.JPEG, 100, baos);

		for (int options = 90; baos.toByteArray().length / 1024 > 100; options -= 10) {
			baos.reset();
			image.compress(CompressFormat.JPEG, options, baos);
		}

		ByteArrayInputStream isBm = new ByteArrayInputStream(baos.toByteArray());
		Bitmap bitmap = BitmapFactory.decodeStream(isBm, (Rect) null, (Options) null);
		return bitmap;
	}

	public static Bitmap compressScale(Bitmap image) {
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		image.compress(CompressFormat.JPEG, 100, baos);
		if (baos.toByteArray().length / 1024 > 1024) {
			baos.reset();
			image.compress(CompressFormat.JPEG, 80, baos);
		}

		ByteArrayInputStream isBm = new ByteArrayInputStream(baos.toByteArray());
		Options newOpts = new Options();
		newOpts.inJustDecodeBounds = true;
		BitmapFactory.decodeStream(isBm, (Rect) null, newOpts);
		newOpts.inJustDecodeBounds = false;
		int w = newOpts.outWidth;
		int h = newOpts.outHeight;
		float hh = 512.0F;
		float ww = 512.0F;
		int be = 1;
		if (w > h && (float) w > ww) {
			be = (int) ((float) newOpts.outWidth / ww);
		} else if (w < h && (float) h > hh) {
			be = (int) ((float) newOpts.outHeight / hh);
		}

		if (be <= 0) {
			be = 1;
		}

		newOpts.inSampleSize = be;
		isBm = new ByteArrayInputStream(baos.toByteArray());
		Bitmap bitmap = BitmapFactory.decodeStream(isBm, (Rect) null, newOpts);
		return compressImage(bitmap);
	}
}